// 主界面
;
define(function(require, exports, module) {
	'use strict';
	var base = require("base");
	var router = require("../hash/pageRouter");
	var effective = false;
	var tools = require("tools");
	var init = function() {
		initEvent();
		//		router.init();
	};
	var initEvent = function() {
		/*新增的点击事件*/
		//		登陆
		$("#content").on("click", "#platform_login", function() {
			tools.protectDoubleClick();
			checkUser();
		});

		document.onkeydown = function(event) {
			if (13 == event.keyCode) {
				checkUser();
			}
		};
	};

	//  登陆方法
	var checkUser = function() {
		var mUsername = $('#platform_username').val().trim();
		var mPassword = $('#platform_password').val().trim();
		if (mUsername == "") {
			$('.error_info').css('visibility', 'visible');
			$('.error_info').html("请输入用户名")
		} else if (mPassword == "") {
			$('.error_info').css('visibility', 'visible');
			$('.error_info').html("请输入密码")
		} else {
			inquireLogisticsCompanyValid(mUsername);
			if (effective == true) {
				base.fnAjax({
					action: "userNameLogin.json",
					version: "v3.0",
					async: false,
					nocode: true,
					oData: {
						username: mUsername,
						password: mPassword,
						appKey: "FINANCE-LOGISTICS-WEB"
					}, //传递参数
					fnSuccess: function(data) {
						tools.cancelProtectDoubleClick();
						if (data.status == 200) {
							base.saveData("sid", data.datas[0].sessionUuid);
							base.saveData("appKey", "FINANCE-LOGISTICS-WEB");
							//存appkey
							base.openUrl("../newTaskList/newTaskList.html");
						} else {
							$('.error_info').css('visibility', 'visible');
							$('.error_info').html(data.message);
						}
					}
				});
			} else {
				return false;
			}

		}
	};

	var inquireLogisticsCompanyValid = function(mUsername) {
		base.fnAjax({
			action: "inquireLogisticsCompanyValid.json",
			version: "v1.0",
			async: false,
			nocode: true,
			oData: {
				appKey: "FINANCE-LOGISTICS-WEB",
				accountName: mUsername
			}, //传递参数
			fnSuccess: function(data) {
				tools.cancelProtectDoubleClick();
				if (data.status == 200) {
					effective = true;
				} else {
					$('.error_info').css('visibility', 'visible');
					$('.error_info').html(data.message);
				}
			}
		});
	};
	return {
		init: init
	};
});